package com.laiketui.user.services.dubbo;

import com.laiketui.common.mapper.UserMapper;
import com.laiketui.domain.user.User;
import com.laiketui.domain.user.UserAddress;
import com.laiketui.root.annotation.DubboApiMethod;
import com.laiketui.core.exception.LaiKeAPIException;
import com.laiketui.user.common.consts.UserConst;
import com.laiketui.user.api.UserService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @description:
 * @author: wx
 * @date: Created in 2019/10/29 11:01
 * @version:
 * @modified By:
 */
@DubboService(version = "1.0.0")
public class UserDubboService implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    @DubboApiMethod(apiKey = "com.laike.user.getUser",
            login = true,module = UserConst.MODULE_NAME ,version = "1.0.0")
    public User getUser(User user) throws LaiKeAPIException {
        User user1 = userMapper.selectByPrimaryKey(user.getId());
        return user1;
    }

    @Override
    @DubboApiMethod(apiKey = "com.laike.user.getUserAddress",
            login = true,module = UserConst.MODULE_NAME ,version = "1.0.0")
    public UserAddress getUserAddress(UserAddress userAddress) throws LaiKeAPIException {
        return null;
    }

    @Override
    @DubboApiMethod(apiKey = "com.laike.user.insert",
            login = true,module = UserConst.MODULE_NAME ,version = "1.0.0")
    public void insertUser(User user) throws LaiKeAPIException {

        userMapper.insert(user);
    }

    @Override
    @DubboApiMethod(apiKey = "com.laike.user.del",
            login = true,module = UserConst.MODULE_NAME ,version = "1.0.0")
    public void deleteUser(User user) throws LaiKeAPIException {
        userMapper.delete(user);
    }

    @Override
    @DubboApiMethod(apiKey = "com.laike.user.modify",
            login = true,module = UserConst.MODULE_NAME ,version = "1.0.0")
    public void uploadUser(User user) throws LaiKeAPIException {
        userMapper.updateByPrimaryKey(user);
    }


    @Override
    public List<User> getUsers() throws LaiKeAPIException {
        return userMapper.selectAll();
    }


}
